* Data sent by BMSGPK (full timeline without certificates)
import delimited "$raw/COVID19_vaccination_municipalities_doses_timeline.csv", encoding(UTF-8) clear
gen dh = date(date,"YMD")
drop date
gen date = dh
format date %td

rename municipality_population mun_pop
gen sh_dose_1 = 100 * dose_1/mun_pop
gen sh_dose_2 = 100 * dose_2/mun_pop
gen sh_dose_3 = 100 * dose_3/mun_pop

sort municipality_id date

gen d7_sh_dose_1 = sh_dose_1 - sh_dose_1[_n-7] if municipality_id==municipality_id[_n-7]
gen d7_sh_dose_2 = sh_dose_2 - sh_dose_2[_n-7] if municipality_id==municipality_id[_n-7]
gen d7_sh_dose_3 = sh_dose_3 - sh_dose_3[_n-7] if municipality_id==municipality_id[_n-7]

gen d14_sh_dose_1 = sh_dose_1 - sh_dose_1[_n-14] if municipality_id==municipality_id[_n-14]
gen d14_sh_dose_2 = sh_dose_2 - sh_dose_2[_n-14] if municipality_id==municipality_id[_n-14]
gen d14_sh_dose_3 = sh_dose_3 - sh_dose_3[_n-14] if municipality_id==municipality_id[_n-14]

* create new folder, if needed
capture mkdir "$edited/vaccination_rates"

save "$edited/vaccination_rate_timeline.dta", replace
